#include "Date.h" 

string Date::date(const char *format)
{
	time_t t = time(0);
	char tmp[64];

	struct tm *ptr;
	ptr = localtime(&t);

	strftime(tmp, sizeof(tmp), format, ptr);

	string datetime_str(tmp);

	return datetime_str;
}

/*
 string Date::date(const char *format)
 {
 time_t t = time(0);

 return Date::date(format, &t);
 }
 */

string Date::date(const char *format, const time_t *t)
{
	char tmp[64];

	struct tm *ptr;
	ptr = localtime(t);

	strftime(tmp, sizeof(tmp), format, ptr);

	string datetime_str(tmp);

	return datetime_str;
}

/*
 int main()
 {
 const char *format = "%Y-%m-%d %H:%M:%S\n";
 string str = Date::date(format);

 printf ("%s", str.c_str());

 str = Date::date("我的测试: %Y-%m-%d \n");

 printf ("%s", str.c_str());
 return 0;
 }
 */

